


import urllib.request
import re
import xlwt


def getdata():
    url_list = []
    for i in range(0, 20):
        url = 'http://furhr.com/?page={}'.format(i)
        html = urllib.request.urlopen(url).read().decode('utf-8')
        # print(html)
        pagelist = re.findall(r'<tr><td>\d+</td><td>\d+</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td></tr>'.html)
        url_list.append(pagelist)

        return url_list


def excel_write(items):
    newtable = '/Users/inrtgdje/Documents/python/text1234.xlsx'
    wb = xlwt.Workbook(encoding=utf - 8)  # 创建excel文件
    ws = wb.add_sheet('text1')
    headDate = ['公司名称', '电话', '地址']
    index = 1
    for colnum in range(0, 3):
        ws.write(0, colnum, headDate[colnum], xlwt.easyxf('font bold on'))

        for item in items:
            for j in range(0, len(item)):
                for i in range(0, 3):
                    print(item[j][i])
                    ws.write(index, i, item[j][i])
                index += 1
        wb.save(newtable)



    items = getdata()
    excel_write(items)
